** FOIA Data Clean
* Jetson Leder-Luis
* False Claims Act Paper

************************************************************
* Read in data with row names
import excel "FOIAData.xlsx", firstrow

* Eliminate 2 stray rows at the bottom
drop if mi(Caption) 

************************************************************
** Case filing date

* There are two dates the DOJ sent me: received date and AG served date
* They can be in either order, so I use the earlier of the two 

gen filingdate = min(ReceivedDate, AGServedDate)
format filingdate %td
gen filingyear = year(filingdate)

*** Tabulate by filing year 
tabulate filingyear

** Drop all cases after 2012, because coverage stops
** We know from DOJ internal statistics cases keep rising, but our cases fall
** That's because these are only completed cases as of the time of the FOIA
drop if filingyear > 2012


************************************************************
*** Clean up election status 
tabulate ElectionStatus
gen intervened = 1 if inlist(ElectionStatus, "Intervened", "Partially Intervened")
replace intervened = 0 if mi(intervened)


************************************************************
** Collapse duplicate cases, i.e. repeating dockets

* First, give unique dockets for cases missing docket numbers 
* So they don't all collapse to 1 case 
replace DocketNumber = string(_n) if mi(DocketNumber)

* Consider cases duplicate if they match in DocketNumber, Filing District, Year
count
collapse (min) filingdate (sum) SJAmount (sum) RelatorShare (max) intervened (first) PrimaryAgency (max) SJDateDismissalDate, by(DocketNumber District filingyear)
count

************************************************************
** Make settlement/judgement variable
gen sj = 1 if SJAmount > 0 
replace sj = 0 if SJAmount == 0 


************************************************************
** Make case length variable
gen caselength =SJDateDismissalDate - filingdate

************************************************************
** Save Clean Case Data
save "FOIADataClean.dta", replace




